package com.simtop;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.simtop.vo.sj.ExamChead;
import com.simtop.vo.sj.ExamList;
import freemarker.template.Configuration;
import freemarker.template.Template;

import java.io.*;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.*;

/**
 * @ClassName: test01
 * @Description TODO
 * @Author liuzhaobo
 * @Date 2022/11/4 0004 14:15
 * @Version 1.0
 **/
public class test02 {
    public static void main(String[] args) {
        try {
            HashMap<String, Object> map = new HashMap<>(4);
            map.put("title","第一次模拟考试");
            map.put("type","第一次模拟考试");

            List<Map<String,Object>> list = new ArrayList<>();
            Map<String, Object> map1 = new HashMap<>();
            map1.put("type", "苹果");
            map1.put("count", 4.5);
            Map<String, Object> map12 = new HashMap<>();
            map1.put("type", "苹果22");
            map1.put("count", 4.522);


            List<Map<String,Object>> list2 = new ArrayList<>();
            Map<String, Object> mapas = new HashMap<>();
            mapas.put("cheadname","dwad");
            mapas.put("cheadoption","nihao");

            Map<String, Object> mapas2 = new HashMap<>();
            mapas2.put("cheadname","dwad223");
            mapas2.put("cheadoption","nihao223");
            list2.add(mapas);
            list2.add(mapas2);
            map1.put("ExamChead" , list2);

            list.add(map1);
            list.add(map12);
            map.put("ExamList", list);

            Configuration configuration = new Configuration();
            configuration.setDefaultEncoding("UTF-8");
            configuration.setDirectoryForTemplateLoading(new File("C:\\Users\\Administrator\\Desktop\\形拓题库系统\\questionbank\\src\\main\\resources\\word"));
            File outFile = new File("D:/test01.doc");
            Template t = configuration.getTemplate("test01.ftl", "utf-8");
            Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"), 10240);
            t.process(map, out);
            out.close();

        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        }

    }

}
